#ifndef TC_SINGLETON_CPP
#define TC_SINGLETON_CPP

/** \file Singleton.cpp
 * Definitions for the class template Singleton.
 *
 * (c) Copyright Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: Singleton.cpp 119 2006-06-21 04:57:25Z semihc $
 *
 *
 */

#ifndef TC_SINGLETON_HPP
# include "Singleton.hpp"
#endif
#include "SingletonMgr.hh"
#include "TypeInfo.hh"



namespace TC {

  template <typename T>
  SingletonMgr* Singleton<T>::s_Manager = 0;
  
  template <typename T>
  T& Singleton<T>::GetInstance()
  {
    if(!s_Manager)
      s_Manager = DefaultSingletonMgr();
    TC_ASSERT(s_Manager);
    T* t = s_Manager->getSingleton<T>();
    TC_ASSERT(t);
    return *t;
  }


  template <typename T>
  unsigned Singleton<T>::GetLongevity()
  {
    TC_ASSERT(s_Manager);
    return s_Manager->getLongevity(typeid(T));
  }
 

  template <typename T>
  void Singleton<T>::SetLongevity(unsigned lgv)
  {
    TC_ASSERT(s_Manager);
    s_Manager->setLongevity(typeid(T),lgv);
  }


  template <typename T>
  void Singleton<T>::DestroyInstance()
  {
    TC_ASSERT(s_Manager);
    s_Manager->destroySingleton(typeid(T));
  }



} // end namespace

#endif /* Include guard */
